/**
 * 一级路由主组件
 */
define("view/main", [
  "vuex",
  "component/wxUtils",
  "component/main/sideMenu",
  "component/main/MainHeader",
  "component/main/FullScreen",
  "component/main/UserInfo",
  "component/main/NavTag",
  "text!./main.html",
  "css!./main.css"
], function(
  { mapMutations, mapActions },
  {
    setTagNavListInLocalstorage,
    getTagNavListFromLocalstorage,
    getNewTagList,
    getNextName
  },
  sideMenu,
  MainHeader,
  FullScreen,
  UserInfo,
  NavTag,
  template
) {
  //console.log(FullScreen);
  return {
    template: template,
    name: "main",
    components: {
      sideMenu,
      MainHeader,
      FullScreen,
      UserInfo,
      NavTag
    },
    data: function() {
      return {
        collapsed: true,
        isFullscreen: false
      };
    },
    methods: {
      ...mapMutations(["setBreadCrumb", "setLocal", "setTagNavList", "addTag"]),
      ...mapActions(["handleLogin"]),
      turnToPage(name) {
        if (name.indexOf("isTurnByHref_") > -1) {
          window.open(name.split("_")[1]);
          return;
        }
        this.$router.push({
          name: name
        });
      },
      handleCollapsedChange(state) {
        //console.log("handleCollapsedChange");
        this.collapsed = state;
      },
      handleCloseTag(res, type, name) {
        const nextName = getNextName(this.tagNavList, name);
        this.setTagNavList(res);
        if (type === "all") this.turnToPage(this.$store.state.homeRoute.name);
        else if (this.$route.name === name)
          this.$router.push({ name: nextName });
      },
      handleClick(item) {
        this.turnToPage(item.name);
      }
    },
    computed: {
      tagNavList() {
        return this.$store.state.tagNavList;
      },
      tagRouter() {
        return this.$store.state.tagRouter;
      },
      userAvator() {
        return this.$store.state.avatorImgPath;
      },
      cacheList() {
        return [];
      },
      menuList() {
        return this.$store.getters.menuList;
      },
      local() {
        return this.$store.state.local;
      }
    },
    created() {},
    watch: {
      $route(newRoute) {
        this.setBreadCrumb(newRoute.matched);
        this.setTagNavList(getNewTagList(this.tagNavList, newRoute));
      }
    },
    mounted() {
      /**
       * @description 初始化设置面包屑导航和标签导航
       */
      this.setTagNavList();
      this.addTag(this.$store.state.homeRoute);
      //console.log(this.$route.matched);
      this.setBreadCrumb(this.$route.matched);
      // 设置初始语言
      //this.setLocal(this.$i18n.locale)
    }
  };
});
